package com.sfhk.web;

import com.sfhk.dao.ProductDao;
import com.sfhk.dao.impl.ProductDaoImpl;
import com.sfhk.domain.Product;
import com.sfhk.service.ProductService;
import com.sfhk.service.impl.ProductServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/ProductListServlet")
public class ProductListServlet extends HttpServlet {
    private ProductService productService = new ProductServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 1.接收请求
        // 2.调用service的方法
        List<Product> list = productService.queryProduct();
        // 3.request域传递数据
        request.setAttribute("list", list);
        // 4.转发到jsp中
        request.getRequestDispatcher("/product_list.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
